var http = require("http");
const path = require("path");
const fs = require("fs");


var arg = process.argv[2];
if(!arg) arg="fileReader1.js";
var filePath = path.join(__dirname,"/" + arg);

http.createServer((reg,res)=>{
    if(fs.existsSync(filePath)){
        fs.readFile(filePath,(err,data)=>{//异步方法
            if(err){
                console.log(err);
            }
            else{
                // res.write(200,{"Content-Type":"text/html;charset=utf-8"});
                res.end(data);
            }
        })
    }
    else{
        res.end("该路径文件不存在");
    }
}).listen(8081);